package com.yuhang.demo.controller;

import com.yuhang.demo.dto.request.ConditionAddRequest;
import com.yuhang.demo.dto.request.ConditionUpdateRequest;
import com.yuhang.demo.dto.response.Result;
import com.yuhang.demo.service.RuleConditionService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/condition")
public class RuleConditionController {

    @Autowired
    private RuleConditionService conditionService;


    /**
     * 新增规则条件
     */
    @PostMapping("/add")
    public Result<Long> addCondition(@Valid @RequestBody ConditionAddRequest request) {
        return conditionService.addCondition(request);
    }

    /**
     * 更新规则条件
     */
    @PutMapping("/update")
    public Result<Boolean> updateCondition(@Valid @RequestBody ConditionUpdateRequest request) {
        return conditionService.updateCondition(request);
    }

    /**
     * 删除规则条件
     */
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteCondition(@PathVariable Long id) {
        return conditionService.deleteCondition(id);
    }

    /**
     * 根据规则ID查询条件列表
     */
    @GetMapping("/list/{ruleId}")
    public Result<?> getConditionByRuleId(@PathVariable Long ruleId) {
        return conditionService.getConditionByRuleId(ruleId);
    }
}
